//
//  LYResumetopView.m
//  SelectCity
//
//  Created by liuyan on 2019/3/28.
//  Copyright © 2019年 liuyan. All rights reserved.
//

#import "LYResumetopView.h"

@interface LYResumetopView()

@property (nonatomic, strong) UIView *lineview;
@property (nonatomic, strong) UILabel *timeLabel;

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *detailLabel;

@property (nonatomic, strong) UILabel *positionLabel;
@property (nonatomic, strong) UIImageView *imageView;

@end


@implementation LYResumetopView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubview];
    }
    return self;
}

- (void)createSubview{
    self.backgroundColor = [UIColor whiteColor];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, WIDTH - 30, 30)];
    titleLabel.font = [UIFont boldSystemFontOfSize:20];
    titleLabel.adjustsFontSizeToFitWidth = YES;
    titleLabel.textColor = RGB(34, 34, 34);
    self.titleLabel = titleLabel;
    [self addSubview:titleLabel];
    
    UILabel *detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.bottom, WIDTH - 30, 16)];
    self.detailLabel = detailLabel;
    detailLabel.font = [UIFont boldSystemFontOfSize:12];
    detailLabel.adjustsFontSizeToFitWidth = YES;
    detailLabel.textColor = RGB(153, 153, 153);
    [self addSubview:detailLabel];
    
    self.lineview = [[UIView alloc] initWithFrame:CGRectMake(0, 69, WIDTH, 1)];
    self.lineview.backgroundColor = RGB(247, 247, 247);
    self.lineview.hidden = YES;
    [self addSubview:self.lineview];
    
    UILabel *positionLabel = [[UILabel alloc] initWithFrame:CGRectMake(15,0, WIDTH - 35, 68)];
    self.positionLabel = positionLabel;
    positionLabel.font = [UIFont boldSystemFontOfSize:15];
    positionLabel.adjustsFontSizeToFitWidth = YES;
    positionLabel.hidden = YES;
    positionLabel.textColor = RGB(153, 153, 153);
    [self addSubview:positionLabel];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectPositon:)];
    [positionLabel addGestureRecognizer:tap];
    
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH-20, 24, 10, 20)];
    self.imageView.hidden = YES;
    self.imageView.image = [UIImage imageNamed:@"jiantou_right"];
    [self addSubview:self.imageView];

    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, _lineview.bottom +5, WIDTH - 30, 20)];
    self.timeLabel.font = [UIFont boldSystemFontOfSize:16];
    self.timeLabel.adjustsFontSizeToFitWidth = YES;
    self.timeLabel.textColor = [UIColor orangeColor];
    self.timeLabel.hidden = YES;
    [self addSubview:self.timeLabel];
}

- (void)setData:(NSDictionary *)dataDic service_aliasType:(NSString *)service_alias jobName:(NSString *)job_name isHtml:(BOOL)isHtml{
    
    if ([service_alias isEqualToString:@"stick_jobs"]) {
        //职位置顶
        self.positionLabel.hidden = NO;
        self.titleLabel.hidden = YES;
        self.detailLabel.hidden = YES;
        if (isHtml) {
            self.imageView.hidden = NO;
            self.positionLabel.userInteractionEnabled = YES;
        }else{
           self.imageView.hidden = YES;
            self.positionLabel.userInteractionEnabled = NO;
        }
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"当前选择职位："];
        NSAttributedString *strq = [[NSAttributedString alloc] initWithString:job_name attributes:@{NSForegroundColorAttributeName :RGB(34, 34, 34),NSFontAttributeName : [UIFont systemFontOfSize:14]}];
        [str appendAttributedString:strq];
        self.positionLabel.attributedText = str;
    }else{
        self.imageView.hidden = YES;
         self.positionLabel.hidden = YES;
        self.titleLabel.hidden = NO;
        self.detailLabel.hidden = NO;
        self.titleLabel.text = dataDic[@"title"];
        self.detailLabel.text = dataDic[@"desc"];
    }
    
    if ([dataDic[@"status"] integerValue] == 1) {
        //已开通服务
        self.lineview.hidden = NO;
        self.timeLabel.hidden = NO;
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@显示中，",dataDic[@"name"]]];
        NSAttributedString *strq = [[NSAttributedString alloc] initWithString:@"到期时间：" attributes:@{NSForegroundColorAttributeName :RGB(153, 153, 153),NSFontAttributeName : [UIFont systemFontOfSize:13]}];
        [str appendAttributedString:strq];
        NSAttributedString *strq1 = [[NSAttributedString alloc] initWithString:[UIToolsControl conversionMonthDayHoursMinuteOrHoursMinute:[dataDic[@"end_time"] integerValue]] attributes:@{NSForegroundColorAttributeName :[UIColor redColor],NSFontAttributeName : [UIFont systemFontOfSize:13]}];
        [str appendAttributedString:strq1];
        self.timeLabel.attributedText = str;
        self.height = 100;
    }else{
        self.lineview.hidden = YES;
        self.timeLabel.hidden = YES;
        self.height = 70;
    }
}
    
    
#pragma mark -- Action
- (void)selectPositon:(UITapGestureRecognizer *)tap{
    _block();
}



@end
